package gold.digger;

import gold.vo.TreeNode;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC112 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public boolean hasPathSum(TreeNode root, int sum) {
            if (root == null) return false;
            if ((root.left == null && root.right == null && root.val == sum)) return true;
            return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
        }
    }

    public void run() {
        Solution solution = new Solution();
        TreeNode root = TreeNode.createTree("5,4,8,11,null,13,4,7,2");
        System.out.println(solution.hasPathSum(null, 0));
    }

    public static void main(String[] args) throws Exception {
        LC112 an = new LC112();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
